package various;


import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;

public class ProvaMotore {
	public static void main(String[] args) throws Exception {

		UltrasonicSensor s = new UltrasonicSensor(SensorPort.S1);
		int a;
		boolean stop = false;

		while (!stop) {

			LCD.clear();
			// LCD.drawString(i+"", 0, 0);
			a = s.getDistance();
			Thread.sleep(500);
			LCD.drawString(a + "", 0, 1);

			while (a > 20) {
				a = s.getDistance();
				LCD.drawString(a + "", 0, 1);
				Motor.A.setSpeed(300);
				Motor.A.forward();
				LCD.drawString("Avanti", 0, 4);
				Thread.sleep(300);
			}
			while (a <= 100 && a > 10) {
				a = s.getDistance();
				LCD.drawString(a + "", 0, 1);
				// Motor.A.setPower(10);
				Motor.A.setSpeed(Motor.A.getTachoCount() * 10);
				Motor.A.backward();
				LCD.drawString("Indietro", 0, 4);
				Thread.sleep(300);
			}

			if (a <= 5) {
				stop = true;
				LCD.clear();
				LCD.drawString("STOP", 5, 5);
			}

		}

	}

}
